class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def generateTrees(self, n):
        """
        :type n: int
        :rtype: List[TreeNode]
        """
        num_list = [i for i in range(1, n + 1)]

        def create_tree(num_list):
            if len(num_list) == 0:
                return [None]
            else:
                if len(num_list) == 1:
                    node = TreeNode(val=num_list[0])
                    return [node]
                else:
                    return_node_list = []
                    for i in range(len(num_list)):
                        left_node_list = create_tree(num_list[: i])
                        right_node_list = create_tree(num_list[i + 1:])
                        for left in left_node_list:
                            for right in right_node_list:
                                node = TreeNode(val=num_list[i])
                                node.left = left
                                node.right = right
                                return_node_list.append(node)
                    return return_node_list

        return create_tree(num_list)


data = Solution()
n = 2
print(data.generateTrees(n))
